import pandas as pd

df1=pd.DataFrame([['张三','a',14,'sh'],
                 ['李四','b',24,'bj'],
                 ['王五','c',44,'hb'],
                 ['赵六','d',32,'hn']],
                 index=['one','two','three','four'],
                 columns=['name','grade','age','city'])
print(df1)
print('---------------')
data1 =df1[['name']][:3]
print('访问name行前三列数据：')
print(data1)
print('---------------')
data3=df1[1:3]##访问一到三行
print(data3)
print('---------------')
data2=df1.loc['two',['name','age']]##访问第二行的name,age
print(data2)
print('---------------')
data4=df1.iloc[2,[3,0,1]]##获取第二行第3，0，1列数据
print(data4)
data5=df1.iloc[:,:3][df1.age>30]
print('访问前三行age大于30的数据\n',data5)